# Contributor: Sergey Fukanchik <fukanchik@gmail.com>
# Maintainer: Leon Bottou <leonb@bottou.org>
pkgname=djvulibre
pkgver=3.5.28
pkgrel=4
pkgdesc="Utilities and Libraries for the DjVu image format"
url="https://djvu.sourceforge.net/"
arch="all"
license="GPL-2.0-only"
makedepends="libjpeg-turbo-dev tiff-dev automake autoconf libtool"
subpackages="$pkgname-dev $pkgname-doc lib$pkgname:libs"
source="https://downloads.sourceforge.net/djvu/djvulibre-$pkgver.tar.gz
	djvulibre-3.5.27-check-image-size.patch
	djvulibre-3.5.27-check-input-pool.patch
	djvulibre-3.5.27-djvuport-stack-overflow.patch
	djvulibre-3.5.27-export-file.patch
	djvulibre-3.5.27-integer-overflow.patch
	djvulibre-3.5.27-out-of-bound-write-2.patch
	djvulibre-3.5.27-unsigned-short-overflow.patch"

# secfixes:
#   3.5.28-r1:
#     - CVE-2021-3500
#     - CVE-2021-3630
#     - CVE-2021-32490
#     - CVE-2021-32491
#     - CVE-2021-32492
#     - CVE-2021-32493

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

libs() {
	pkgdesc="Runtime support for the DjVu image format"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.so.* \
		"$subpkgdir"/usr/lib/
}

sha512sums="
db3b8a5b56d700e911be32057f721a2a597e6f52e6fade203ad75ad76ab2d8facff2e474fd18beea703ccd5fa6425352e619a8fda40e69add1724dbee26050c6  djvulibre-3.5.28.tar.gz
f73f0fe6e8a3a38b617ca4085c4a1ff88d9a0a9ba1c1501856d2b489388b624535901d9fb7387a052b922eeda441cdddef16198ae6beeac7d691d27be8691eb4  djvulibre-3.5.27-check-image-size.patch
5cc31f7c02972de99d413601e9ae31fb32e63ba6427163fb04fb522f479e5ed737ddbf122d3dbf541a3e1ecfb42870ed315dc7f5ce620a392efe72c08475e9b9  djvulibre-3.5.27-check-input-pool.patch
52feb4b1f3db515fb3228287ddfb82ef62c9ddd85e1f3cae551a25e21e402f69ceec38133aabb9a581ad6fbc113ef65e7297f0bdbe34fb75077314e5cc40a2d7  djvulibre-3.5.27-djvuport-stack-overflow.patch
b7a05df01060376079a0c59df2ecf20efddbd1b08e42c99e18ed94e89481c1850393488de39421bd8f31b6c6ce647a11b29b1a98306f121584792fc1b040e698  djvulibre-3.5.27-export-file.patch
9c1bdfcfcc003076cf9effd5a2d4df04e5ab9b9f891ab0ee7f0f5d7fcd5c83f605bd1e3e0be51132c18fa91900f49c2f7165b8426490c522a5a8f59e9d9e09e3  djvulibre-3.5.27-integer-overflow.patch
69ad8be81c20bf02bec3426a42c90ff9aafba38ed216f8563434aa7921fbd45973981c07076208374f637fb9e6e4a9b58e8639337288b6b34b2dbee77ff6eac1  djvulibre-3.5.27-out-of-bound-write-2.patch
ff08cc6e21053c42454e3855095d6fbea6a7e99924b2e977dd723df6e63f09d3375c4db88bd678a576d635b34a5e19358f766af59eeedfbdb7c62cde2d6962bf  djvulibre-3.5.27-unsigned-short-overflow.patch
"
